package com.cssy.authority.dao.impl;

import com.cssy.authority.dao.RoleDAO;
import com.cssy.authority.entity.Role;
import com.cssy.authority.entity.RoleExample;
import com.ibatis.sqlmap.client.SqlMapClient;
import java.sql.SQLException;
import java.util.List;

public class RoleDAOImpl implements RoleDAO {
    private SqlMapClient sqlMapClient;

    public RoleDAOImpl(SqlMapClient sqlMapClient) {
        super();
        this.sqlMapClient = sqlMapClient;
    }

    public void insert(Role record) throws SQLException {
        sqlMapClient.insert("sc_role.abatorgenerated_insert", record);
    }

    public int updateByPrimaryKey(Role record) throws SQLException {
        int rows = sqlMapClient.update("sc_role.abatorgenerated_updateByPrimaryKey", record);
        return rows;
    }

    public int updateByPrimaryKeySelective(Role record) throws SQLException {
        int rows = sqlMapClient.update("sc_role.abatorgenerated_updateByPrimaryKeySelective", record);
        return rows;
    }

    public List selectByExample(RoleExample example) throws SQLException {
        List list = sqlMapClient.queryForList("sc_role.abatorgenerated_selectByExample", example);
        return list;
    }

    public Role selectByPrimaryKey(Long id) throws SQLException {
        Role key = new Role();
        key.setId(id);
        Role record = (Role) sqlMapClient.queryForObject("sc_role.abatorgenerated_selectByPrimaryKey", key);
        return record;
    }

    public int deleteByExample(RoleExample example) throws SQLException {
        int rows = sqlMapClient.delete("sc_role.abatorgenerated_deleteByExample", example);
        return rows;
    }

    public int deleteByPrimaryKey(Long id) throws SQLException {
        Role key = new Role();
        key.setId(id);
        int rows = sqlMapClient.delete("sc_role.abatorgenerated_deleteByPrimaryKey", key);
        return rows;
    }

    public int countByExample(RoleExample example) throws SQLException {
        Integer count = (Integer)  sqlMapClient.queryForObject("sc_role.abatorgenerated_countByExample", example);
        return count.intValue();
    }

    public int updateByExampleSelective(Role record, RoleExample example) throws SQLException {
        UpdateByExampleParms parms = new UpdateByExampleParms(record, example);
        int rows = sqlMapClient.update("sc_role.abatorgenerated_updateByExampleSelective", parms);
        return rows;
    }

    public int updateByExample(Role record, RoleExample example) throws SQLException {
        UpdateByExampleParms parms = new UpdateByExampleParms(record, example);
        int rows = sqlMapClient.update("sc_role.abatorgenerated_updateByExample", parms);
        return rows;
    }

    private static class UpdateByExampleParms extends RoleExample {
        private Object record;

        public UpdateByExampleParms(Object record, RoleExample example) {
            super(example);
            this.record = record;
        }

        public Object getRecord() {
            return record;
        }
    }

	@Override
	public List<Role> selectByExample(String permissionid) throws SQLException {
		  List list = sqlMapClient.queryForList("sc_role.abatorgenerated_selectByPermissionId", permissionid);
	        return list;
	}
}